package org.czl.tree;

public class l {
    //摩尔投票
    public int majorityElement(int[] nums) {
        int x = 0;
        int count = 0;
        for(int i : nums){
            if(i == x){
                count++;
            }else if(count == 0){
                x = i;
                count = 1;
            }else{
                count--;
            }

        }
        return x;
    }
}
